package SiTuQingYou.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import SiTuQingYou.dao.PackCarDao;
import SiTuQingYou.util.Pager;
import SiTuQingYou.vo.PackCar;
import SiTuQingYou.vo.User;

/**
 * Servlet implementation class MyShoppingcartServlet
 */
@WebServlet("/MyShoppingcartServlet")
public class MyShoppingcartServlet extends BaseAction {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MyShoppingcartServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    //根据用户id查询出购物车内容
    protected void lookForAllShoppingcart(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
   		// TODO Auto-generated method stubr
   		HttpSession session = request.getSession();
   		User user = (User)session.getAttribute("user");
   		
   		Pager pager = Pager.init(request);
   		ArrayList<PackCar> allsc = PackCarDao.getpcd().lookForAllById(user.getId(),pager);
    	request.setAttribute("allsc",allsc);
    	
   	}
    
    
    //删除选中的攻略
    protected void deleteAllChecked(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	String cid[] = request.getParameterValues("cid");
    	PackCarDao.getpcd().deleteAllChecked(cid);
    	
    	//重新查询数量，并且传给jsp页面
    	HttpSession session = request.getSession();
    	User user = (User)session.getAttribute("user");
    	int count = PackCarDao.getpcd().getShoppingCartCount(user.getId());
    	PrintWriter out = response.getWriter();
 	    out.print(count);
    }
    
    
    @Override
   	protected void doDefault(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
   		// TODO Auto-generated method stubr
   		
   	}

}
